import numpy as np

x = np.arange(1, 11, 1)
print(x)
print(x.shape) # 查看x的形状
print(x.size) # 输出x的大小

x.shape = 2, 5 # 将x改为2行5列
print(x)
print(x.shape) # 输出x改变后的形状

x.shape = 5, -1 # -1表示自动计算 -> 5行2列
print(x.shape)
print(x)

a = x.reshape(2, 5) # reshape返回新的数组
print('原数组:\n', x) # 5行2列
print('新数组:\n', a) # 2行5列

x = np.array(range(5)) # 生成数组0 - 4
print(x)

# x.reshape((1, 10)) # reshape()不能修改数组元素个数 -> ERR

# x.resize((1, 10)) # resize()可以修改数组元素个数
print(x) # 不够的会补充0

x.resize((1, 3))
print(x) # 超出的大小会删除

x.resize((1, 10))
print(x)

res = np.resize(x, (1, 3)) # resize()返回新数组，不对原数组进行任何修改
print('原数组:\n', x)
print('新数组:\n', res)

